package lab;

public class PunnetHelper {
	public static String[] getBorder(String s){
		String[] types = s.split(",");
		for (int i = 0; i < types.length; i++)types[i] = types[i].toLowerCase();
		String[] result = new String[(int) Math.pow(2,types.length)];
		for (int i = 0; i < result.length; i++){
			result[i] = "";
			for (int j = 0; j < types.length; j++){
				double ii = (Math.pow(2, j+1));
				double jj = ii/2 - .5;
				if (i%ii > jj)result[i]+=types[j].toUpperCase();
				else result[i]+=types[j].toLowerCase();
			}
		}
		return result;
	}
	
	public static int getPosition(String[] genes, int p){
		int l = genes.length;
		int min = 0;
		int max = (int) Math.pow(2, l)-1;
		int c = 0;
		while(min!=max){
			String res = genes[c].charAt(p)+"";
			if (res.equals(res.toUpperCase())) min = (max+min)/2 + 1;
			else max = (max+min)/2;
			c++;
		}
		return min;
	}
}
